selecao = nil
filename = "../user_preferences"

function create_file()
	file, err = io.open(filename, "r")

	if (err ~= nil) then
		print('[t-cup]: Creating new user preferences file...')

		file = io.open(filename, "w")
		file:write("tela_preferida=principal:0;grupos:0;matamata:0\n")
		file:write("gruposAB=0:0\n")
		file:write("gruposCD=0:0\n")
		file:write("gruposEF=0:0\n")
		file:write("gruposGH=0:0\n")
		file:write("sua_selecao=brazil\n")
	end

	file:close()
end

function load_team()
	print('[t-cup]: Loading team')

	create_file()
	for line in io.open(filename):lines() do
		key, value = string.match(line, "^([a-zA-Z_]*)%=([a-zA-Z]*)$")
		if (key == 'sua_selecao') then
			selecao = value
			break		end
	end

	local time = canvas:new("../media/bandeiras-legendas/" .. selecao .. ".png")
	canvas:compose(130, 45, time)
	canvas:flush()end

load_team()
